/**
 * 天气预报android开源系统V1.0(武汉永恒成就信息科技有限公司)
 * @author:Hu yunbo
 * Email :yunboh@gmail.com
 * Time:2011年2月17日
 */


package com.android.weather.View;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;

import Weather.Test.R;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

/**
 * 天气信息类
 * @author Hu yunbo
 *
 */
public class SingleWeatherInfoView extends LinearLayout {

	
	private ImageView myWeatherImageView = null;
	private TextView myWeatherTextView = null;
	public SingleWeatherInfoView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	
	public SingleWeatherInfoView(Context context,AttributeSet attrs)
	{
		super(context,attrs);
		this.myWeatherImageView = new ImageView(context);
		this.myWeatherImageView.setImageDrawable(getResources().getDrawable(R.drawable.dunno));
		
		this.myWeatherTextView = new TextView(context);
		this.myWeatherTextView.setText("? C");
		this.myWeatherTextView.setTextSize(16);
		this.myWeatherTextView.setTypeface(Typeface.create("Tahoma", Typeface.BOLD));
	
		this.addView(this.myWeatherImageView, new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT
		));
		
		this.addView(this.myWeatherTextView,new LinearLayout.LayoutParams(
				LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT
		));
	
	}
	
	public void reset()
	{
		this.myWeatherImageView.setImageDrawable(getResources().getDrawable(R.drawable.dunno));
		this.myWeatherTextView.setText("? C");
		
	}
	
	public void setRemoteImage(URL aURL)
	{
		try
		{
			URLConnection conn = aURL.openConnection();
			conn.connect();
			InputStream is = conn.getInputStream();
			BufferedInputStream bis = new BufferedInputStream(is);
			Bitmap bm = BitmapFactory.decodeStream(bis);
			bis.close();
			is.close();
			this.myWeatherImageView.setImageBitmap(bm);
		}
		catch(IOException e)
		{
			this.myWeatherImageView.setImageDrawable(getResources().getDrawable(R.drawable.dunno));
		}
	}
	
	public void setTempCelcius(int aTemp)
	{
		this.myWeatherTextView.setText(""+aTemp+"C");
	}
	public void setTempFahrenheit(int aTemp)
	{
		this.myWeatherTextView.setText(""+aTemp+"F");
	}
	
	public void setTempFahrenheitMinMax(int aMinTemp,int aMaxTemp)
	{
		this.myWeatherTextView.setText(""+aMinTemp +"/"+aMaxTemp+"F");
	}
	
	public void setTempCelciusMinMax(int aMinTemp,int aMaxTemp)
	{
		this.myWeatherTextView.setText(""+aMinTemp+"/"+aMaxTemp+"C");
	}
	public void setTempString(String aTempString)
	{
		this.myWeatherTextView.setText(aTempString);
	}
	
	
}
